package com.apes.fn.scm.used.repository;

import com.apes.fn.scm.used.model.Used;
import com.apes.framework.jpa.repository.CustomRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface UsedRepository extends CustomRepository<Used, String> {

    Used findFirstByName(String name);

    Used findFirstByNameAndIdIsNot(String name, String id);

    @Query(value = "SELECT * from WAR_USED WHERE ID in (SELECT USED_ID from WAR_USED_CLASSIFY WHERE CLASSIFY_ID = :classifyId)",nativeQuery = true)
    Page<Used> find(@Param("classifyId")String classifyId, Pageable pageable);

    @Query(value = "SELECT * from WAR_USED WHERE ID in (SELECT USED_ID from WAR_USED_CLASSIFY WHERE CLASSIFY_ID = 'M01010102001' OR CLASSIFY_ID = 'M01010105001') AND VALID = 1",nativeQuery = true)
    Page<Used> findByClassify(Pageable pageable);
}
